< previous page page_352 next page >

Page 352
These agree with the blending functions presented in the previous section. To make these equations match up properly with the previous versions, the endpoints must be the data points numbered 0 and 3. The additional control points must be data points 1 and 2.
Using the generalized equation for the Bezier blending functions, you can write a Visual Basic program to create a Bezier curve that uses many control points. To make the code a bit easier to understand, create separate functions to compute factorials and the blending function values for inputs i, N, and t. Then use these functions to compute X(t) and Y(t). The drawing routine DrawCurve can use these functions as before.
e10a6a0a59f035e870d90cca05b85fce.gif
' Return the factorial of a number.
Private Function Factorial(ByVal N As Integer) As Long 
Dim value As Long 
Dim i As Integer 

    value = 1
    For i = 2 To N
        value = value * i
    Next i
    Factorial = value
End Function

' The blending function for i, N, and t.
Private Function Blend(ByVal i As Integer, _
    ByVal N As Integer, ByVal t As Single) As Single

    Blend = Factorial(N) / Factorial(i) / _
        Factorial(N - i) * t ^ i * (1 - t) ^ (N - i)
End Function

' The parametric function X(t).
Private Function X(ByVal t As Single) As Single
Dim i As Integer 
Dim value As Single 

    For i = 0 To MaxPt 
        value = value + PtX(i) * Blend(i, MaxPt, t) 
    Next i 
    X = value 
End Function 

' The parametric function Y(t). 
Private Function Y(ByVal t As Single) As Single 
Dim i As Integer 
Dim value As Single 

    For i = 0 To MaxPt 
        value = value + PtY(i) * Blend(i, MaxPt, t) 
    Next i
    Y = value
End Function

 
< previous page page_352 next page >